package com.gzxw.mogublog.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzxw.mogublog.admin.annotation.OperationLogger.OperationLogger;
import com.gzxw.mogublog.commons.entity.Admin;
import com.gzxw.mogublog.commons.entity.CategoryMenu;
import com.gzxw.mogublog.utils.R;
import com.gzxw.mogublog.xo.service.CategoryMenuService;
import com.gzxw.mogublog.xo.vo.CategoryMenuVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/categoryMenu")
public class CategoryMenuController {

    @Autowired
    private CategoryMenuService categoryMenuService;

    @PostMapping("/getList")
    public R getList(@RequestBody CategoryMenuVO categoryMenuVO) {
        IPage<CategoryMenu> pageList = categoryMenuService.getPageList(categoryMenuVO);
        Map<String, Object> result = new HashMap<>();
        List<CategoryMenu> records = pageList.getRecords();
        long total = pageList.getTotal();
        long size = pageList.getSize();
        long current = pageList.getCurrent();
        result.put("records", records);
        result.put("total", total);
        result.put("size", size);
        result.put("current", current);
        return R.success("200", result);
    }

    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    public R getAll(@RequestParam("keyword") String keyword) {

       List<CategoryMenu> pageList = categoryMenuService.getAllList(keyword);
       Map<String ,Object> result = new HashMap<>();
       result.put("records",pageList);

       return R.success("返回成功",result);
    }

    @RequestMapping(value = "/getButtonAll", method = RequestMethod.GET)
    public R getButtonAll(@RequestParam(value = "keyword", required = false) String keyword) {

        List<CategoryMenu> pageList = categoryMenuService.getButtonAllList(keyword);
        Map<String ,Object> result = new HashMap<>();
        result.put("records",pageList);

        return R.success("返回成功",result);
    }

    @OperationLogger("添加菜单/权限")
    @PostMapping("/add")
    public R add(@RequestBody CategoryMenuVO categoryMenuVO) {

        String message = categoryMenuService.addCategoryMenu(categoryMenuVO);

        return R.success("200",message);
    }

    @OperationLogger("编辑菜单/权限")
    @PostMapping("/edit")
    public R edit(@RequestBody CategoryMenuVO categoryMenuVO) {

        String message = categoryMenuService.editCategoryMenu(categoryMenuVO);

        return R.success("200",message);
    }

    @OperationLogger("删除菜单/权限")
    @PostMapping("/delete")
    public R delete(@RequestBody CategoryMenuVO categoryMenuVO) {

        String message = categoryMenuService.deleteCategoryMenu(categoryMenuVO);

        return R.success("200",message);
    }

    @OperationLogger("顶置菜单/权限")
    @PostMapping("/stick")
    public R stick(@RequestBody CategoryMenuVO categoryMenuVO) {

       String message =  categoryMenuService.stickCategoryMenu(categoryMenuVO);

        return R.success("200",message);
    }


}
